﻿using System;
using System.Text;

namespace _3.CheckExpression
{
    class CheckExpression
    {
        static void Main()
        {
            Console.Write("Enter expression: ");
            string str = Console.ReadLine();
            bool isvalid = CheckExpression_(str);
            Console.WriteLine("Expression valid? {0}", isvalid);
        }
        private static bool CheckExpression_(string s)
        {
            int openbrackets = 0, closedbrackets = 0; //opened and closed bracket's counters
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '(') openbrackets++;
                if (s[i] == ')') closedbrackets++;
            }
            if (openbrackets == closedbrackets) return true;
            return false;
        }
    }
}
